package com.spring.hot;

/**
 * @author Cizai
 * @since 2022/12/07 10:25
 * @see <a href="https://leetcode.cn/problems/rotate-image/?favorite=2cktkvj">...</a>
 **/
public class 旋转图像 {

    // 先转置再镜像

    public void rotate(int[][] matrix) {

        //int left = matrix.length-1;
        //int j = matrix[0].length-1;

        for (int i = 0; i < matrix.length; i++) {
            for (int j = i; j < matrix[i].length; j++) {
                int temp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = temp;
            }
        }

        int left = 0;
        int right = matrix[0].length-1;

        while (left < right) {
            for (int i = 0;i < matrix.length; i++) {
                int temp = matrix[i][left];
                matrix[i][left] = matrix[i][right];
                matrix[i][right] = temp;
            }
            left++;
            right--;
        }


    }
}
